import { sysLogin, sysProfile,sysUser } from '@/api/user'

export default {
  namespaced: true,
  state: {
    token: '',
    userInfo: '' //  用户信息
  },
  mutations: {
    // 修改token

    setToken(state, value) {
      state.token = value
    },

    //  修改用户信息

    setUserInfo(state, value) {
      state.userInfo = value
    },
    //  删除token与用户信息
    logout(state) {
      state.token = ''
      state.userInfo = ''
    }
  },
  actions: {
    async toLogin(store, form) {
      const res = await sysLogin(form)

      store.commit('setToken', res.data)
    },

    //  获取用户信息
    async getUserInfo(store) {
      const res = await sysProfile()
      //  获取用户其他信息
      const res2 =await sysUser(res.data.userId)


     const resultRes=Object.assign({},res.data,res2.data)
      store.commit('setUserInfo',resultRes)


      console.log('用户信息',resultRes)
    }
  },
  getters: {}
}
